import request from '@/utils/request'

/**
 * 获取文章列表信息
 * @param {*} id 频道ID
 * @param {*} timestamp 时间戳
 * @returns
 */
export const getArticleList = (id, timestamp) => {
  return request({
    method: 'get',
    url: '/v1_1/articles',
    params: {
      channel_id: id,
      timestamp,
      with_top: 1
    }
  })
}

/**
 * 对文章不感兴趣
 * @param {*} id 文章的Id
 * @returns
 */
export function dislikeArticle (id) {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 举报文章
 * @param {*} id 文章的Id
 * @param {*} type 举报的类型
 * @returns
 */
export function reportArticle (id, type) {
  return request({
    method: 'post',
    url: '/v1_0/article/reports',
    data: {
      target: id,
      type
    }
  })
}
/**
 * 获取文章详情
 * @param {*} id
 * @returns
 */
export function getArticleDetail (id) {
  return request({
    method: 'get',
    url: '/v1_0/articles/' + id
  })
}
/**
 * 关注用户
 * @param {*} id  作者id
 * @returns
 */
export function followUser (id) {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}
/**
 * 取消关注
 * @param {*} id 作者id
 * @returns
 */
export function unfollowUser (id) {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}
/**
 * 点赞文章
 * @param {*} id 文章id
 * @returns
 */
export function addlike (id) {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}
/**
 * 取消点赞
 * @param {*} id 文章id
 * @returns
 */
export function deleteLike (id) {
  return request({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}
/**
 * 添加文章不喜欢
 * @param {*} id 文章id
 * @returns
 */
export function addDislike (id) {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
/**
 * 取消文章不喜欢
 * @param {*} id 文章id
 * @returns
 */
export function deleteDislike (id) {
  return request({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 获取文章评论
 * @param {*} articleId 文章的id
 * @param {*} offset 上一次返回的Id,如果是第一页，可以为null
 * @returns
 */
export function getCommentList (articleId, offset) {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: articleId,
      offset: offset
    }
  })
}
/**
 * 发表文章的评论
 * @param {*} articleId
 * @param {*} content
 * @returns
 */
export function addComment (articleId, content) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}
/**
 * 给文章的评论点赞
 * @param {*} commentId 评论的id
 * @returns
 */
export function addCommentZan (commentId) {
  return request({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}
/**
 * 取消给评论的点赞
 * @param {*} commentId 评论的id
 * @returns
 */
export function deleteCommentZan (commentId) {
  return request({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + commentId
  })
}
/**
 * 获取回复列表
 * @param {*} commentId
 * @param {*} offset
 * @returns
 */
export function getReplyList (commentId, offset) {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source: commentId,
      offset
    }
  })
}

/**
 * 添加回复接口
 * @param {*} commentId
 * @param {*} content
 * @param {*} articleId
 * @returns
 */
export function addReply (commentId, content, articleId) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: commentId,
      content,
      art_id: articleId
    }
  })
}
